"""
存放的是后台添加商品页面的相关用例
"""
import unittest
import ddt
from Page.addgoods_page import *
from common.databaseTool import DatabaseTool
from common.openExcel import *
from common import cfg


filePath = os.path.dirname(__file__) + r"/testData/添加商品测试数据.xlsx"
essinfo = Open_excel(filePath, "必填项", {"price": str})
essinfoData = essinfo.read()
goods_names = [essinfo.get_column(0), ]
addgoods_re = Open_excel(filePath, "必填项不合格", {"price": str})
addgoods_reData = addgoods_re.read()
goods_names.append(addgoods_re.get_column(0))
name_style = Open_excel(filePath, "商品字体", {"price": str})
name_styleData = name_style.read()
goods_names.append(name_style.get_column(0))
goods_sn = Open_excel(filePath, "商品货号", {"price": str, "goods_sn": str})
goods_snData = goods_sn.read()
goods_names.append(goods_sn.get_column(0))
goods_sn_re = Open_excel(filePath, "商品货号不合格", {"price": str, "goods_sn": str})
goods_sn_reData = goods_sn_re.read()
goods_names.append(goods_sn_re.get_column(0))
addcat = Open_excel(filePath, "添加分类")
addcatData = addcat.read()
cats = addcat.get_column(0)
addbrand = Open_excel(filePath, "添加品牌")
addbrandData = addbrand.read()
brands = addbrand.get_column(0)
choosbrand = Open_excel(filePath, "选择品牌", {"price": str})
choosbrandData = choosbrand.read()
goods_names.append(addbrand.get_column(0))
choossupplier = Open_excel(filePath, "选择供货商", {"price": str})
choossuppliersData = choossupplier.read()
goods_names.append(choossupplier.get_column(0))
user_price = Open_excel(filePath, "会员价格", {"price": str, "price1": str, "price2": str, "price3": str})
user_priceData = user_price.read()
goods_names.append(user_price.get_column(0))
market_price = Open_excel(filePath, "市场价格", {"price": str, "market_price": str})
market_priceData = market_price.read()
goods_names.append(market_price.get_column(0))
market_price_re = Open_excel(filePath, "市场价格不合格", {"price": str, "market_price": str})
market_price_reData = market_price_re.read()
goods_names.append(market_price_re.get_column(0))
market_price_refl = Open_excel(filePath, "市场价格取整", {"price": str})
market_price_reflData = market_price_refl.read()
goods_names.append(market_price_refl.get_column(0))
market_set_price = Open_excel(filePath, "按市场价格", {"price": str})
market_set_priceData = market_price.read()
goods_names.append(market_set_price.get_column(0))
goods_num = Open_excel(filePath, "虚拟销量", {"price": str, "sale_num": str})
goods_numData = goods_num.read()
goods_names.append(goods_num.get_column(0))
goods_num_re = Open_excel(filePath, "虚拟销量不合格", {"price": str, "sale_num": str})
goods_num_reData = goods_num.read()
goods_names.append(goods_num_re.get_column(0))
promote_price = Open_excel(filePath, "促销价格", {"price": str, "promote_price": str})
promote_priceData = promote_price.read()
goods_names.append(promote_price.get_column(0))
promote_price_re = Open_excel(filePath, "促销价格不合格", {"price": str, "promote_price": str})
promote_price_reData = promote_price_re.read()
goods_names.append(promote_price_re.get_column(0))
promote_date = Open_excel(filePath, "促销日期", {"price": str, "promote_price": str, "time_start": str, "time_end": str})
promote_dateData = promote_date.read()
goods_names.append(promote_date.get_column(0))
promote_date_re = Open_excel(filePath, "促销日期不合格",
                             {"price": str, "promote_price": str, "time_start": str, "time_end": str})
promote_date_reData = promote_date_re.read()
goods_names.append(promote_date_re.get_column(0))
goods_img_upload = Open_excel(filePath, "商品图片", {"price": str, "imgPath": str})
goods_img_uploadData = goods_img_upload.read()
goods_names.append(goods_img_upload.get_column(0))
goods_img_upload_re = Open_excel(filePath, "商品图片不合格", {"price": str, "imgPath": str})
goods_img_upload_reData = goods_img_upload_re.read()
goods_names.append(goods_img_upload_re.get_column(0))
goods_weight = Open_excel(filePath, "商品重量", {"price": str, "weight": str})
goods_weightData = goods_weight.read()
goods_names.append(goods_weight.get_column(0))
goods_weight_re = Open_excel(filePath, "商品重量不合格", {"price": str, "weight": str})
goods_weight_reData = goods_weight_re.read()
goods_names.append(goods_weight_re.get_column(0))
goods_number = Open_excel(filePath, "商品库存", {"price": str, "goods_number": str})
goods_numberData = goods_number.read()
goods_names.append(goods_number.get_column(0))
goods_number_re = Open_excel(filePath, "商品库存不合格", {"price": str, "weight": str})
goods_number_reData = goods_number_re.read()
goods_names.append(goods_number_re.get_column(0))
warn_number = Open_excel(filePath, "库存警告", {"price": str, "weight": str})
warn_numberData = warn_number.read()
goods_names.append(warn_number.get_column(0))
warn_number_re = Open_excel(filePath, "库存警告不合格", {"price": str, "weight": str})
warn_number_reData = warn_number_re.read()
goods_names.append(warn_number_re.get_column(0))
keywords = Open_excel(filePath, "商品关键词", {"price": str, "weight": str})
keywordsData = keywords.read()
goods_names.append(keywords.get_column(0))
goods_brief = Open_excel(filePath, "简单描述", {"price": str, "weight": str})
goods_briefData = goods_brief.read()
goods_names.append(goods_brief.get_column(0))
goods_brief_re = Open_excel(filePath, "简单描述不合格", {"price": str, "weight": str})
goods_brief_reData = goods_brief_re.read()
goods_names.append(goods_brief_re.get_column(0))
seller_note = Open_excel(filePath, "商家备注", {"price": str, "weight": str})
seller_noteData = seller_note.read()
goods_names.append(seller_note.get_column(0))
goods_type = Open_excel(filePath, "商品类型", {"price": str, "weight": str})
goods_typeData = goods_type.read()
goods_names.append(goods_type.get_column(0))


@ddt.ddt
class AddGoodsCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        # 预制条件:
        cls.db = DatabaseTool(**cfg.database)
        sql1 = "delete from ecs_goods where goods_name=%s"
        cls.db.execute_many(sql1, goods_names)
        sql2 = "delete from ecs_category where cat_name=%s"
        cls.db.execute_many(sql2, cats)
        sql3 = "delete from ecs_brand where brand_name=%s"
        cls.db.execute_many(sql3, brands)

    def setUp(self):
        #     2. 打开谷歌浏览器,进入ecshop后台的登录页面
        self.driver = open_browser()
        self.ad = AddGoodsPage(self.driver)
        self.ad.open_url(login_url)
        self.ad.get_background(cfg.admin_username, cfg.admin_password)
        self.ad.get_add_goods()

    def tearDown(self):
        # 关闭浏览器
        self.ad.quit()

    @classmethod
    def tearDownClass(cls):
        # 还原数据库
        sql = "delete from ecs_goods where goods_name=%s"
        cls.db.execute_many(sql, goods_names)
        sql = "delete from ecs_category where cat_name=%s"
        cls.db.execute_many(sql, cats)
        sql = "delete from ecs_brand where brand_name=%s"
        cls.db.execute_many(sql, brands)

    def test_add_goods_turn(self):
        '''
        测试添加商品页面跳转
        '''
        title = self.ad.get_element_text(("id", "search_id"))
        self.assertIn("添加新商品", title, msg="页面跳转失败,未跳转至添加商品页面")

    @ddt.data(*essinfoData)
    def test_addgoods(self, Data):
        '''
        测试必填项添加商品
        '''
        self.ad.currencyInfo_need(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = "select goods_name from ecs_goods"
        goods_names = [i["goods_name"] for i in self.db.fetchAll(sql)]
        self.assertIn(Data["goods_name"], goods_names, msg="用例执行失败,新增的商品未找到")

    @ddt.data(*addgoods_reData)
    def test_addgoods_re(self, Data):
        '''
        测试必填项不合格添加商品
        '''
        try:
            self.ad.currencyInfo_need(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = "select goods_name from ecs_goods"
            goods_names = [i["goods_name"] for i in self.db.fetchAll(sql)]
            self.assertNotIn(Data["goods_name"], goods_names, msg="用例执行失败")

    @ddt.data(*name_styleData)
    def test_name_style(self, Data):
        """
        测试商品名称显示字体
        :param Data:
        :return:
        """
        self.ad.name_style(**Data)
        sleep(5)
        sql = f"select goods_name_style from ecs_goods where goods_name={Data['goods_name']}"
        name_styles = [i["name_style"] for i in self.db.fetchAll(sql)]
        self.assertEqual(Data["name_style"], name_styles, msg="失败,添加的商品名称字体未找到")

    @ddt.data(*goods_snData)
    def test_goods_sn_001(self, Data):
        """
        测试输入商品货号
        :param Data:
        :return:
        """
        try:
            self.ad.goods_sn(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(0, msg="用例执行失败,商品未添加成功")
        else:
            sleep(5)
            sql = f"select goods_sn from ecs_goods where goods_name={Data['goods_name']} order by last_update desc limit 1"
            goods_sn = self.db.fetchOne(sql)["goods_sn"]
            self.assertEqual(Data["goods_sn"], goods_sn, msg="用例执行失败,添加商品的货号不正确")

    @ddt.data(*goods_sn_reData)
    def test_goods_sn_002(self, Data):
        """
        测试输入不合理的商品货号
        :param Data:
        :return:
        """
        try:
            self.ad.goods_sn(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"select goods_sn from ecs_goods where goods_name={Data['goods_name']} order by last_update desc limit 1"
            goods_sn = self.db.fetchOne(sql)["goods_sn"]
            self.assertNotEqual(Data["goods_sn"], goods_sn, msg="用例执行失败,不合格商品货号添加成功")

    @ddt.data(*addcatData)
    def test_addcat(self, Data):
        """
        测试商品分类的添加
        :param Data:
        :return:
        """
        self.ad.add_cat(**Data)
        sleep(5)
        sql = "select cat_name from ecs_category"
        cat_names = [i["cat_name"] for i in self.db.fetchAll(sql)]
        self.assertIn(Data["catName"], cat_names, msg="用例执行失败,新增的分类未找到")

    def test_cat_turn(self):
        """
        测试分类管理的页面跳转
        :return:
        """
        self.ad.cat_turn()
        title = self.ad.get_element_text(("id", "search_id"))
        self.assertIn("添加分类", title, msg="用例执行失败,未跳转至分类管理页面")

    @ddt.data(*addbrandData)
    def test_addbrand(self, Data):
        """
        测试品牌的添加功能
        :param Data:
        :return:
        """
        self.ad.add_brand(**Data)
        sleep(5)
        sql = "select brand_name from ecs_brand"
        brands_name = [i["brand_name"] for i in self.db.fetchAll(sql)]
        self.assertIn(Data["brand_name"], brands_name, msg="用例执行失败,新增的分类未找到")

    def test_brand_turn(self):
        """
        测试品牌添加页面跳转
        :return:
        """
        self.ad.brand_turn()
        title = self.ad.get_element_text(("id", "search_id"))
        self.assertIn("添加品牌", title, msg="用例执行失败,未跳转至分类管理页面")

    @ddt.data(*choosbrandData)
    def test_brand_choose(self, Data):
        """
        测试品牌选择
        :param Data:
        :return:
        """
        self.ad.brand_choose(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select brand_name from ecs_goods where goods_name={Data['goods_name']}"
        brands_name = self.db.fetchOne(sql)["brand_name"]
        self.assertEqual(Data["brandName"], brands_name, msg="用例执行失败,选择的品牌不正确")

    @ddt.data(*choossuppliersData)
    def test_suppliers_choose(self, Data):
        """
        测试供货商的选择
        :param Data:
        :return:
        """
        self.ad.suppliers_choose(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select provider_name from ecs_goods where goods_name={Data['goods_name']}"
        supplier_name = self.db.fetchOne(sql)["provider_name"]
        self.assertEqual(Data["supplier_name"], supplier_name, msg="用例执行失败,选择的供货商不正确")

    @ddt.data(*user_priceData)
    def test_price_set(self, Data):
        """
        测试本店价格的输入
        :param Data:
        :return:
        """
        self.ad.price_set(**Data)
        self.ad.click_sure()
        sleep(5)
        sql1 = f"""select user_price from ecs_member_price join ecs_goods using(goods_id) where goods_name={Data[
            'goods_name']} and user_rank=1"""
        sql2 = f"""select user_price from ecs_member_price join ecs_goods using(goods_id) where goods_name={Data[
            'goods_name']} and user_rank=2"""
        sql3 = f"""select user_price from ecs_member_price join ecs_goods using(goods_id) where goods_name={Data[
            'goods_name']} and user_rank=3"""
        user_price1 = self.db.fetchOne(sql1)["user_price"]
        user_price2 = self.db.fetchOne(sql2)["user_price"]
        user_price3 = self.db.fetchOne(sql3)["user_price"]
        self.assertEqual(Data["user_price1"], user_price1, msg="用例执行失败,保存的会员价格不正确")
        self.assertEqual(Data["user_price2"], user_price2, msg="用例执行失败,保存的代销价格不正确")
        self.assertEqual(Data["user_price3"], user_price3, msg="用例执行失败,保存的vip价格不正确")

    @ddt.data(*market_priceData)
    def test_market_price(self, Data):
        """
        测试市场价格的输入
        :param Data:
        :return:
        """
        self.ad.market_price(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select market_price from ecs_goods where goods_name={Data['goods_name']}"
        market_price = self.db.fetchOne(sql)["market_price"]
        self.assertEqual(Data["market_price"], market_price, msg="用例执行失败,保存的市场价格不正确")

    @ddt.data(*market_price_reflData)
    def test_market_price_refl(self, Data):
        """
        测试市场价格取整
        :param Data:
        :return:
        """
        self.ad.market_price_refl(**Data)
        sleep(5)
        sql = f"select market_price from ecs_goods where goods_name={Data['goods_name']}"
        market_price = self.db.fetchOne(sql)["user_price"]
        self.assertFalse(market_price - int(market_price), msg="用例执行失败,保存的市场价格未取整")

    @ddt.data(*market_set_priceData)
    def test_market_set_price_001(self, Data):
        """
        测试安市场价格设置商品价格
        :param Data:
        :return:
        """
        self.ad.market_set_price(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select market_price from ecs_goods where goods_name={Data['goods_name']}"
        market_price = self.db.fetchAll(sql)["market_price"]
        self.assertEqual(Data["market_price"], market_price, msg="用例执行失败,按市场价格新增的商品未找到")

    @ddt.data(*market_set_priceData)
    def test_market_set_price_002(self, Data):
        """
        测试不合格市场价格
        :param Data:
        :return:
        """
        try:
            self.ad.market_set_price(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        finally:
            sleep(5)
            sql = f"select market_price from ecs_goods where goods_name={Data['goods_name']}"
            market_price = self.db.fetchAll(sql)["market_price"]
            self.assertNotEqual(Data["market_price"], market_price, msg="用例执行失败,按市场价格新增的商品未找到")

    @ddt.data(*goods_numData)
    def test_goods_num_001(self, Data):
        """
        测试商品虚拟销量
        :param Data:
        :return:
        """
        self.ad.goods_num(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select virtual_sales from ecs_goods where goods_name={Data['goods_name']}"
        goods_number = [i["goods_number"] for i in self.db.fetchAll(sql)]
        self.assertEqual(Data["goods_number"], goods_number, msg="用例执行失败,新增的商品虚拟销量不正确")

    @ddt.data(*goods_num_reData)
    def test_goods_num_002(self, Data):
        """
        测试输入不合理的商品虚拟销量
        :param Data:
        :return:
        """
        try:
            self.ad.goods_num(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        finally:
            sleep(5)
            sql = f"select virtual_sales from ecs_goods where goods_name={Data['goods_name']}"
            goods_number = self.db.fetchOne(sql)["virtual_sales"]
            self.assertNotEqual(Data["goods_number"], goods_number, msg="用例执行失败,不合格的商品虚拟销量新增成功")

    def test_promote_clickless(self):
        """
        测试不选中促销按钮设置促销数据
        :return:
        """
        promote = self.ad.click_promote()
        promote.click()
        promote_stm = self.ad.get_promote_stm()
        promote_etm = self.ad.get_promote_etm()
        self.assertFalse(promote_stm.is_enabled(), msg="用例执行失败")
        self.assertFalse(promote_etm.is_enabled(), msg="用例执行失败")

    @ddt.data(*promote_priceData)
    def test_set_promote_price_001(self, Data):
        """
        测试促销价格设置
        :param Data:
        :return:
        """
        self.ad.promote_price(**Data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select promote_price from ecs_goods where goods_name={Data['goods_name']}"
        promote_price = self.db.fetchOne(sql)["promote_price"]
        self.assertEqual(Data["promote_price"], promote_price, msg="用例执行失败,促销价格新增成功")

    @ddt.data(*promote_priceData)
    def test_set_promote_price_002(self, Data):
        """
        测试不合理的促销价格设置
        :param Data:
        :return:
        """
        try:
            self.ad.promote_price(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"select promote_price from ecs_goods where goods_name={Data['goods_name']}"
            promote_price = self.db.fetchOne(sql)["promote_price"]
            self.assertNotEqual(Data["promote_price"], promote_price, msg="用例执行失败,促销价格新增成功")

    @ddt.data(*promote_dateData)
    def test_promote_date_001(self, Data):
        """
        测试促销日期设置
        :param Data:
        :return:
        """
        self.ad.set_promote_time(**Data)
        self.ad.click_sure()
        sleep(5)
        sql1 = f"select promote_start_date from ecs_goods where goods_name={Data['goods_name']}"
        sql2 = f"select promote_end_date from ecs_goods where goods_name={Data['goods_name']}"
        promote_start_date = self.db.fetchOne(sql1)["promote_start_date"]
        promote_end_date = self.db.fetchOne(sql2)["promote_end_date"]
        self.assertEqual(Data["time_start"], promote_start_date, msg="用例执行失败,促销价格新增成功")
        self.assertEqual(Data["time_end"], promote_end_date, msg="用例执行失败,促销价格新增成功")

    @ddt.data(*promote_date_reData)
    def test_promote_date_002(self, Data):
        """
        测试不合理的促销日期设置
        :param Data:
        :return:
        """
        try:
            self.ad.set_promote_time(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql1 = f"""select promote_start_date from ecs_goods where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            sql2 = f"""select promote_end_date from ecs_goods where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            promote_start_date = self.db.fetchOne(sql1)["promote_start_date"]
            promote_end_date = self.db.fetchOne(sql2)["promote_end_date"]
            self.assertNotEqual(Data["time_start"], promote_start_date, msg="用例执行失败,促销价格新增成功")
            self.assertNotEqual(Data["time_end"], promote_end_date, msg="用例执行失败,促销价格新增成功")

    def test_img_thumb(self):
        '''
        测试缩略图自动生成能否上传缩略图
        :return:
        '''
        goods_thumb = self.ad.get_goods_thumb()
        self.ad.click(goods_thumb)
        goods_thumb_up = self.ad.get_thumb_up()
        goods_thumb_urlup = self.ad.get_thumb_urlup()
        self.assertFalse(goods_thumb_up.is_enabled(), msg="用例执行失败")
        self.assertFalse(goods_thumb_urlup.is_enabled(), msg="用例执行失败")

    @ddt.data(*goods_img_uploadData)
    def test_goods_img_upload_001(self, Data):
        """
        测试商品图片上传
        :param Data:
        :return:
        """
        try:
            self.ad.goods_img_upload(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(0, msg="用例执行失败,商品图片上传失败")
        else:
            sleep(5)
            sql = f"""select goods_img from ecs_goods where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            goods_img = self.db.fetchOne(sql)["goods_img"]
            if "/" not in goods_img:
                path = os.path.dirname(__file__) + f"/testData/{Data['goods_img']} order by goods_sn desc limit 1"
            self.assertEqual(path, goods_img, msg="用例执行失败,商品图片地址不正确")

    @ddt.data(*goods_img_upload_reData)
    def test_goods_img_upload_002(self, Data):
        """
        测试上传不合理的商品图片
        :param Data:
        :return:
        """
        try:
            self.ad.goods_img_upload(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"""select goods_img from ecs_goods where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            goods_img = self.db.fetchOne(sql)["goods_img"]
            if "/" not in goods_img:
                path = os.path.dirname(__file__) + f"/testData/{Data['goods_img']}"
            self.assertEqual(path, goods_img, msg="用例执行失败")

    @ddt.data(*essinfoData)
    def test_minute(self, Data):
        """
        测试商品详细描述
        :param Data:
        :return:
        """
        self.ad.minuteInfo(**Data, content="这是这件商品的详细描述信息")
        self.ad.click_sure()
        sleep(5)
        sql = f"select goods_desc from ecs_goods where goods_name={Data['goods_name']} order by last_update desc limit 1"
        goodsdesc = self.db.fetchOne(sql)["goods_desc"]
        self.assertEqual(Data["goods_desc"], goodsdesc, msg="用例执行失败,商品详细信息录入失败")

    def test_other_turnless(self):
        """
        测试不切换页面输入
        :return:
        """
        try:
            self.ad.other_turnless("20")
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            self.assertTrue(0, msg="用例执行失败,向页面无法显示的输入框成功输入了数据")

    @ddt.data(*goods_weightData)
    def test_weight_001(self, data):
        """
        测试商品重量的设置
        :param data:
        :return:
        """
        self.ad.other_weight(**data)
        self.ad.click_sure()
        sleep(10)
        sql = f"select goods_weight from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        goods_weight = self.db.fetchOne(sql)["goods_desc"]
        self.assertEqual(data["weight"], goods_weight, msg="用例执行失败,商品重量录入不正确")

    @ddt.data(*goods_weight_reData)
    def test_weight_002(self, data):
        """
        测试不合理的商品重量的设置
        :param data:
        :return:
        """
        try:
            self.ad.other_weight(**data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(10)
            sql = f"""select goods_weight from ecs_goods where goods_name={data[
                'goods_name']} order by last_update desc limit 1"""
            goods_weight = self.db.fetchOne(sql)["goods_desc"]
            self.assertEqual(data["weight"], goods_weight, msg="用例执行失败,错误的商品重量录入成功")

    @ddt.data(*goods_numberData)
    def test_goods_number_001(self, data):
        """
        测试商品库存
        :param data:
        :return:
        """
        self.ad.goods_number(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select goods_number from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        good_number = self.db.fetchOne(sql)["goods_number"]
        self.assertEqual(data["goods_number"], good_number, msg="用例执行失败,商品库存录入失败")

    @ddt.data(*goods_number_reData)
    def test_goods_number_002(self, data):
        """
        测试不合理的商品库存
        :param data:
        :return:
        """
        try:
            self.ad.goods_number(**data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(10)
            sql = f"""select goods_number from ecs_goods where goods_name={data[
                'goods_name']} order by last_update desc limit 1"""
            good_number = self.db.fetchOne(sql)["goods_number"]
            self.assertNotEqual(data["goods_number"], good_number, msg="用例执行失败,不正确的商品库存录入成功")

    @ddt.data(*warn_numberData)
    def test_warn_number_001(self, data):
        """
        测试库存警告
        :param data:
        :return:
        """
        self.ad.warn_number(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select warn_number from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        warn_numbers = self.db.fetchOne(sql)["warn_number"]
        self.assertEqual(data["warn_number"], warn_numbers, msg="用例执行失败,警告库存录入失败")

    @ddt.data(*warn_number_reData)
    def test_warn_number_002(self, data):
        """
        测试不合理的库存警告设置
        :param data:
        :return:
        """
        try:
            self.ad.warn_number(**data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"""select warn_number from ecs_goods where goods_name={data[
                'goods_name']} order by last_update desc limit 1"""
            warn_numbers = self.db.fetchOne(sql)["warn_number"]
            self.assertNotEqual(data["warn_number"], warn_numbers, msg="用例执行失败,不正确警告库存录入成功")

    @ddt.data(*essinfoData)
    def test_is_best(self, data):
        """
        测试精品设置
        :param data:
        :return:
        """
        self.ad.is_best(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select is_best from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        is_best = self.db.fetchOne(sql)["is_best"]
        self.assertTrue(is_best, msg="用例执行失败,精品未设置成功")

    @ddt.data(*essinfoData)
    def test_is_new(self, data):
        """
        测试新品设置
        :param data:
        :return:
        """
        self.ad.is_new(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select is_new from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        is_new = self.db.fetchOne(sql)["is_new"]
        self.assertTrue(is_new, msg="用例执行失败,新品未设置成功")

    @ddt.data(*essinfoData)
    def test_is_on_sale(self, data):
        """
        测试上架设置
        :param data:
        :return:
        """
        self.ad.is_on_sale(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select is_on_sale from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        is_on_sale = self.db.fetchOne(sql)["is_new"]
        self.assertTrue(is_on_sale, msg="用例执行失败,上架未设置成功")

    @ddt.data(*essinfoData)
    def test_is_shipping(self, data):
        """
        测试包邮设置
        :param data:
        :return:
        """
        self.ad.is_shipping(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select is_shipping from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        is_shipping = self.db.fetchOne(sql)["is_shipping"]
        self.assertTrue(is_shipping, msg="用例执行失败,包邮未设置成功")

    @ddt.data(*warn_numberData)
    def test_keywords_001(self, data):
        """
        测试关键词设置
        :param data:
        :return:
        """
        self.ad.keywords(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select keywords from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        keywords = self.db.fetchOne(sql)["keywords"]
        self.assertEqual(data["keywords"], keywords, msg="用例执行失败,关键词录入不正确")

    @ddt.data(*goods_briefData)
    def test_goods_brief_001(self, data):
        """
        测试商品简单描述设置
        :param data:
        :return:
        """
        self.ad.goods_brief(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select goods_brief from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        goods_brief = self.db.fetchOne(sql)["goods_brief"]
        self.assertEqual(data["goods_brief"], goods_brief, msg="用例执行失败,简单描述录入失败")

    @ddt.data(*goods_brief_reData)
    def test_goods_brief_002(self, data):
        """
        测试不合理简单描述
        :param data:
        :return:
        """
        try:
            self.ad.goods_brief(**data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"""select goods_brief from ecs_goods where goods_name={data[
                'goods_name']} order by last_update desc limit 1"""
            goods_brief = self.db.fetchOne(sql)["goods_brief"]
            self.assertNotEqual(data["goods_brief"], goods_brief, msg="用例执行失败,不正确简单描述录入成功")

    @ddt.data(*seller_noteData)
    def test_seller_note_001(self, data):
        """
        测试商家备注设置
        :param data:
        :return:
        """
        self.ad.seller_note(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"select seller_note from ecs_goods where goods_name={data['goods_name']} order by last_update desc limit 1"
        seller_note = self.db.fetchOne(sql)["seller_note"]
        self.assertEqual(data["seller_note"], seller_note, msg="用例执行失败,商家备注录入不正确")

    def test_attr_turnless(self):
        """
        测试不切换页面输入
        :return:
        """
        try:
            self.ad.attr_turnless("书")
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            self.assertTrue(0, msg="选择了页面无法显示的下拉框数据")

    @ddt.data(*goods_typeData)
    def test_goods_type_001(self, data):
        """
        测试商品类型设置
        :param data:
        :return:
        """
        self.ad.goods_type(**data)
        self.ad.click_sure()
        sleep(5)
        sql = f"""select cat_name from ecs_goods join ecs_goods_type using (cat_id) where goods_name={data[
            'goods_name']} order by last_update desc limit 1"""
        cat_name = self.db.fetchOne(sql)["cat_name"]
        self.assertEqual(data["goods_type"], cat_name, msg="用例执行失败,商家备注录入不正确")
        sql = f"""delete from ecs_goods join ecs_goods_type using (cat_id) where goods_name={data[
            'goods_name']}"""
        self.db.fetchOne(sql)

    def test_album_turnless(self):
        """
        测试不切换页面输入
        :return:
        """
        try:
            self.ad.album_turnless("图片描述")
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            self.assertTrue(0, msg="用例执行失败,向页面无法显示的输入框成功输入了数据")

    @ddt.data(*essinfoData)
    def test_img_desc_001(self, data):
        """
        测试相册描述设置
        :param data:
        :return:
        """
        self.ad.album_img_desc(**data, img_desc="相册描述")
        self.ad.click_sure()
        sleep(5)
        sql = f"""select img_desc from ecs_goods right join ecs_goods_gallery using (goods_id) where goods_name={data[
            'goods_name']} order by last_update desc limit 1"""
        img_desc = self.db.fetchOne(sql)["img_desc"]
        self.assertEqual("相册描述", img_desc, msg="用例执行失败,相册描述录入不正确")
        sql = f"""delete from ecs_goods join ecs_goods_gallery using (goods_id) where goods_name={data[
            'goods_name']}"""
        self.db.fetchOne(sql)

    @ddt.data(*goods_img_uploadData)
    def test_album_img_url_001(self, Data):
        """
        测试商品相册上传
        :param Data:
        :return:
        """
        try:
            self.ad.album_img_url(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(0, msg="用例执行失败,相册图片上传失败")
        else:
            sleep(5)
            sql = f"""select img_url from ecs_goods join ecs_goods_gallery using (goods_id) where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            img_url = self.db.fetchOne(sql)["goods_img"]
            if "/" not in img_url:
                path = os.path.dirname(__file__) + f"/testData/{Data['goods_img']} order by goods_sn desc limit 1"
            self.assertEqual(path, img_url, msg="用例执行失败,相册图片地址不正确")
        sql = f"""delete from ecs_goods join ecs_goods_gallery using (goods_id) where goods_name={Data[
            'goods_name']}"""
        self.db.fetchOne(sql)

    @ddt.data(*goods_img_upload_reData)
    def test_album_img_url_002(self, Data):
        """
        测试不合理图片上传商品相册
        :param Data:
        :return:
        """
        try:
            self.ad.album_img_url(**Data)
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            sleep(5)
            sql = f"""select goods_img from ecs_goods where goods_name={Data[
                'goods_name']} order by last_update desc limit 1"""
            goods_img = self.db.fetchOne(sql)["goods_img"]
            if "/" not in goods_img:
                path = os.path.dirname(__file__) + f"/testData/{Data['goods_img']}"
            self.assertEqual(path, goods_img, msg="用例执行失败")

    @ddt.data(*essinfoData)
    def test_reset(self, data):
        """
        测试重置按钮
        :param data:
        :return:
        """
        self.ad.click_reset(**data)
        try:
            self.ad.click_sure()
        except Exception as e:
            self.assertTrue(1, msg=e)
        else:
            self.assertTrue(0, msg="用例执行失败")


if __name__ == '__main__':
    unittest.main()
